package infiews.web;

import infiews.crawler.Crawler;

import java.util.Date;
import java.util.regex.Pattern;

public class Site {
	
	private int threads = Crawler.getConfig().getInt("site.default.threads");
	private int deep = Crawler.getConfig().getInt("site.default.deep");
	private String pattern = Crawler.getConfig().getString("site.default.pattern");
	private Date lastUpdate;
	private String namespace;
	private String startUrls;
	private boolean active;
	private Pattern urlPattern;
    private boolean usingXPath;
    private String encoding;
    private String xPath;
	
	public Site( String namespace ){
		this.namespace = namespace;
	}
	
	public void setThreads(int threads) {
		this.threads = threads;
	}

	public int getThreads() {
		return threads;
	}

	public void setDeep(int deep) {
		this.deep = deep;
	}

	public int getDeep() {
		return deep;
	}

	public void setActive( boolean active ){
		this.active = active;
	}
	
	public boolean getActive( ){
		return this.active;
	}
	
	public void setPattern(String pattern) {
		this.pattern = pattern;
	}

	public Pattern getPattern() {
		if(urlPattern == null)
			urlPattern = Pattern.compile(pattern);
		return urlPattern;
	}

	public String getPatternAsString(){
		return pattern;
	}

	public void setLastUpdate(Date lastUpdate) {
		this.lastUpdate = lastUpdate;
	}

	public Date getLastUpdate() {
		return lastUpdate;
	}

	public void setStartUrl(String startUrls) {
		this.startUrls = startUrls;
	}

	public String[] getStartUrls() {
		return startUrls.split(";");
	}

	public String getStartUrlsAsString(){
		return startUrls;
	}
	
	public String getNamespace(){
		return namespace;
	}

    public boolean isUsingXPath(){
        return usingXPath;
    }

    public void setUseXPath(boolean isUse){
        usingXPath = isUse;
    }

    public void setEncoding(String newEncoding){
        encoding = newEncoding;
    }

    public String getEncoding(){
        if (encoding!="" && encoding!=null){
            return encoding;
        } else {
            return Crawler.getConfig().getString("crawler.default_encoding");
        }
    }

    public void setXPath(String newXPath){
        xPath = newXPath;
    }

    public String getXPath(){
        return xPath;
    }
	 
}
